<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link rel="stylesheet" type="text/css" href="../../css/mui.css"/>
		<link href="../../css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" type="text/css" href="../../css/general.css"/>
		<style type="text/css">
			
			.mui-ellipsis{
				display: flex;
				align-items: center;
				justify-content: space-between;
				font-size: 0.9em;
			}
			.fright {
    height: 3.4em;
    background-color: #007AFF;
    text-align: center;
    width: 100%;
    line-height: 3.4em;
    color: white;
}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav hbg">
		    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left colorw"></a>
		    <h1 class="mui-title" id="headerid">修改库存</h1>
		</header>
		<div class="mui-content">
		    <div class="main" id="plistid">
				<!--
                	作者：592176224@qq.com
                	时间：2019-02-22
                	描述：
              
				<ul class="mui-table-view">
				    <li class="mui-table-view-cell mui-media">
				        <a href="javascript:;">
				            <img class="mui-media-object mui-pull-left" src="http://placehold.it/40x30">
				            <div class="mui-media-body">
				                幸福            ￥100
				                <div class="mui-ellipsis">
				                	现有库存：10000
				                	<div class="mui-numbox" data-numbox-step="1" data-numbox-min="0" data-numbox-max="100000">
				                	    <button class="mui-btn mui-btn-numbox-minus" type="button">-</button>
				                	    <input class="mui-input-numbox" type="number" />
				                	    <button class="mui-btn mui-btn-numbox-plus" type="button">+</button>
				                	</div>
				                	
				                </div>
				            </div>
				        </a>
				    </li>
				</ul>
				  -->
				  
				  
		    </div>
		    
		    
		    <div class="footdiv">
		    	<div class="fright" id="subut">
		    		确定
		    	</div>
		    </div>
		</div>
		<script src="../../js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../js/mui.min.js"></script>
		<script src="../../js/req.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../js/muishow.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			var plist = [],dotype = 1,product = [];
			window.onload = function(){
				mui.init();
				
				var list = getrequest().list;
				//console.log(2);
				//console.log(list);
				plist = JSON.parse(list);
				var header = g("headerid");
				//console.log(plist.dotype)
				
				mui.plusReady(function(res){
					 var view = plus.webview.currentWebview();
					 plist = view;
				})
				if(plist.dotype == 1 || plist.dotype == "1"){
					header.innerHTML = "入库"
				}else{
					header.innerHTML = "出库"
				}
				
				setplist(plist.goods);
				
				g("subut").addEventListener("tap",function(res){
					var list = plist.goods
					for(var i = 0; i < list.length; i++){
						var str = {
							product_id:list[i].pid,
							count:g("number"+i).value,
							price:list[i].price
						}
						product.push(str);
					}
					//console.log(product);
					edit_stock(product);
				})
			}
			function edit_stock(product){
				var data = {
						url:"/api/product/edit_stock",
						data:{
							access_token:acctoken(),
							do_type:plist.dotype,
							product:product
						}
					}
					ajax(data,function(res){
						console.log(res);
						mui.toast(res.msg);
						setTimeout(function(res){
							var cPage = plus.webview.currentWebview();
						    var bPage = cPage.opener();
						    bPage.evalJS("onshow();");
							mui.back();
						},0)
					})
				
				
			}
			function setplist(list){
				console.log(list);
				var str = '<ul class="mui-table-view">';
				for(var i = 0; i < list.length; i++){
				    str += '<li class="mui-table-view-cell mui-media">'+
				        '<a href="javascript:;">';
				        if(list[i].pimg.length > 40){
				        	str += '<img class="mui-media-object mui-pull-left" src="'+list[i].pimg+'">';
				        }else{
				        	str += '<img class="mui-media-object mui-pull-left" src="../../img/noimg.png">';
				        }
				        str += '<div class="mui-media-body">'+
				        list[i].pname + '  |  '+ list[i].price+
				        '<div class="mui-ellipsis">现有库存：'+
				        list[i].pstock +
	                	'<div class="mui-numbox" data-numbox-step="1" data-numbox-min="0" data-numbox-max="100000">'+
	                	    '<button class="mui-btn mui-btn-numbox-minus" type="button">-</button>'+
	                	    '<input class="mui-input-numbox" id="number'+i+'" type="number" />'+
	                	    '<button class="mui-btn mui-btn-numbox-plus" type="button">+</button>'+
	                	'</div></div></div></a></li>';
				}
				str += '</ul>'
				
				g("plistid").innerHTML = str;
				mui('.mui-numbox').numbox();
				
			}
			function gocomset(rid){
				var list = {rid: rid}
				mui.openWindow({
				    url: 'commission-set.html?rid='+rid, 
				    id: 'commission-set',
				    extras: list,
				 });
			}
		</script>
	</body>

</html>